﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public static class LogHelper
    {

        public static void Info<T>(T info)
        {
            WriteColorLine(info, ConsoleColor.White);
        }

        public static void Error<T>(T info)
        {
            WriteColorLine(info, ConsoleColor.Red);
        }

        public static void Success<T>(T info)
        {
            WriteColorLine(info, ConsoleColor.Green);
        }

        public static void Warning<T>(T info)
        {
            WriteColorLine(info, ConsoleColor.Green);
        }

        private static void WriteColorLine<T>(T info, ConsoleColor color)
        {
            ConsoleColor currentForeColor = Console.ForegroundColor;
            Console.ForegroundColor = color;
            Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}--{(info?.GetType() == typeof(string) ? info : JsonConvert.SerializeObject(info))}");
            Console.ForegroundColor = currentForeColor;
        }
    }
}
